package com.mxin.image.glide;

import android.content.Context;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

import androidx.annotation.NonNull;

@GlideModule
public class CustomGlideModule extends AppGlideModule {

    private static IGlideModelListener glideModelListener;

    public static IGlideModelListener getGlideModelListener() {
        if(glideModelListener==null){
            return new DefaultGlideModelImpl();
        }else{
            return glideModelListener;
        }
    }

    public static void setGlideModelListener(IGlideModelListener glideModelListener) {
        CustomGlideModule.glideModelListener = glideModelListener;
    }

    @Override
    public boolean isManifestParsingEnabled() {
        return false;
    }

    @Override
    public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
        getGlideModelListener().registerComponents(context, glide, registry);
    }

    @Override
    public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
        super.applyOptions(context, builder);
        getGlideModelListener().applyOptions(context, builder);
    }
}
